<?php
	class phongbandb
	{
		public function Add($TenPhongBan, $MoTa, $DienThoai)
		{
			$sql = "INSERT INTO `tbl_phongban` (`TenPhongBan`, `MoTa`, `DienThoai`) 
			VALUES ('$TenPhongBan', '$MoTa', $DienThoai)";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaPhongBan)
		{
			$sql = "DELETE FROM `tbl_phongban` WHERE MaPhongBan = $MaPhongBan";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaPhongBan, $TenPhongBan, $MoTa, $DienThoai)
		{
			$sql = "UPDATE `tbl_phongban` 
					SET `TenPhongBan`='$TenPhongBan', 
						`MoTa`='$MoTa',
						`DienThoai`='$DienThoai'
					WHERE `MaPhongBan`=$MaPhongBan";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function GetList($MaPhongBan, $TenPhongBan, $MoTa, $DienThoai)
		{
			$sql = "SELECT * FROM `tbl_phongban` WHERE 1";
			if($MaPhongBan != 0)
				$sql .= " AND MaPhongBan = $MaPhongBan";
			
			if($TenPhongBan != "")
				$sql .= " AND TenPhongBan LIKE '%$TenPhongBan%'";
			
			if($MoTa != "")
				$sql .= " AND MoTa LIKE '%$MoTa%'";
				
			if($DienThoai != "")
				$sql .= " AND DienThoai LIKE '%$DienThoai%'";
				
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
	}
?>